package com.max.baselib.widget.toolbar

import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.appcompat.widget.Toolbar
import com.max.baselib.widget.toolbar.ToolbarConstants.Companion.def_titleStyle_NaN
import com.mxin.ui.R

/**
 *  Created by ：2020/7/27
 *  author : Administrator
 *  Toolbar 标题文字居左
 */
open class ToolbarHelperLeftTitle(view:View) : ToolbarHelper<Toolbar>(view){

    override fun isSelfView(view: View): Boolean {
        return view is Toolbar
    }

    override fun createView(attachView: View, styleResId:Int): Toolbar {
        titleView = Toolbar(ContextThemeWrapper(attachView.context , styleResId))
        return titleView
    }

    override fun setTitle(title: String?, titleStyle: Int) {
        titleView.title = title
        if(titleStyle != def_titleStyle_NaN){
            titleView.setTitleTextAppearance(titleView.context, titleStyle)
        }
    }

    override fun getDefaultTitleStyle(): Int {
        return R.style.toolbarTitleStyle
    }

    override fun build(){
        if(titleView.context is AppCompatActivity) {
            (titleView.context as AppCompatActivity).setSupportActionBar(titleView)
        }
        titleView.setBackgroundColor(bgColor)
        setTitle(title, titleStyle)
        if(showNavigation){
            titleView.setNavigationIcon(navigationIcon)
        }
        if(navigationClickListener!=null){
            titleView.setNavigationOnClickListener(navigationClickListener)
        }
        if(menuResId != ToolbarConstants.def_menuResId_NaN){
            titleView.inflateMenu(menuResId)
        }
    }
}